﻿//----------------------------------------------------------------
// <copyright file="ResourcesBLL.cs" >
//    Copyright (c) Wenzy , All rights reserved.
//    author:温正宇 E-Mail:wenzy@tom.com　MyBlog:wenzy.cnblogs.com
//    All rights reserved.
// </copyright>
//----------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Data;
using MemberShipDAL.DataObject;

namespace WMFConfig.Bussiness
{
    class ResourcesBLL
    {
        /// <summary>
        /// 绑定资源树，递归算法
        /// </summary>
        /// <param name="trv_Resources"></param>
        public bool ResourcesTreeBind(string parentId, TreeNode pNode, DataTable dsResources, TreeView trv_Resources)
        {
            DataView dvTree = new DataView(dsResources);

            if (parentId != "")
            {
                dvTree.RowFilter = "[ParentId] ='" + parentId + "'";
            }
            else
            {
                dvTree.RowFilter = "[ParentId] is null";
            }

            foreach (DataRowView row in dvTree)
            {
                TreeNode tn = new TreeNode();
                tn.Name = row["ResourceGroupId"].ToString();
                tn.Text = row["ResourcesGroupName"].ToString();
                tn.ToolTipText = row["Description"].ToString();
                
                if (pNode == null)
                {
                    trv_Resources.Nodes.Add(tn);
                    trv_Resources.SelectedNode = tn;
                    ResourcesTreeBind(row["ResourceGroupId"].ToString(), tn, dsResources, trv_Resources);
                }
                else
                {
                    pNode.Nodes.Add(tn);
                    ResourcesTreeBind(row["ResourceGroupId"].ToString(), tn, dsResources, trv_Resources);
                }
            }
            return true;
        }
    }
}
